
package com.killcalorie.wjduan.auth


import com.killcalorie.wjduan.auth.dto.UserAuth

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.core.userdetails.UsernameNotFoundException
import org.springframework.stereotype.Service


@Service
class AuthenticationService(val jwtUserRepository: UserRepository? = null) : UserDetailsService {
    @Throws(UsernameNotFoundException::class)
    override fun loadUserByUsername(email: String): UserDetails? {

        val user = jwtUserRepository!!.findUserByEmail(email)?: throw UsernameNotFoundException("User not found with email: $email")

        return org.springframework.security.core.userdetails.User(user.email, user.password, ArrayList())
    }
}